import request from '@/utils/request'

// 获取角色列表
export function getRoleList(params) {
  return request({
    url: '/role/roleList',
    method: 'get',
    params
  })
}

// 分页查询角色
export function getRolePage(params) {
  return request({
    url: '/role/pageRole',
    method: 'get',
    params
  })
}

// 获取角色详情
export function getRoleDetail(id) {
  return request({
    url: `/role/getRoleById/${id}`,
    method: 'get'
  })
}

// 添加角色
export function addRole(data) {
  return request({
    url: '/role/addRole',
    method: 'post',
    data
  })
}

// 更新角色
export function updateRole(data) {
  return request({
    url: '/role/updateRole',
    method: 'put',
    data
  })
}

// 删除角色
export function deleteRole(id) {
  return request({
    url: `/role/deleteRole/${id}`,
    method: 'delete'
  })
}

// 批量删除角色
export function deleteBatchRole(ids) {
  return request({
    url: '/role/deleteBatch',
    method: 'post',
    data: ids
  })
}

// 分配权限
export function assignPermissions(data) {
  return request({
    url: '/role/assignPermissions',
    method: 'post',
    data: {
      roleId: data.roleId,
      permissionIds: data.permissionIds
    }
  })
}

// 获取角色权限
export function getRolePermissions(roleId) {
  return request({
    url: `/role/permissions/${roleId}`,
    method: 'get'
  })
}

// 更新角色状态
export function updateRoleStatus(data) {
  return request({
    url: '/role/updateStatus',
    method: 'post',
    data
  })
}

// 数据权限分配
export function setDataScope(data) {
  return request({
    url: '/role/dataScope',
    method: 'post',
    data
  })
}

// 查询角色已分配的用户列表
export function getRoleUserList(params) {
  return request({
    url: '/role/authUser/allocatedList',
    method: 'get',
    params
  })
}

// 查询角色未分配的用户列表
export function getUnallocatedUserList(params) {
  return request({
    url: '/role/authUser/unallocatedList',
    method: 'get',
    params
  })
}

// 批量分配用户角色
export function authUserSelectAll(data) {
  return request({
    url: '/role/authUser/selectAll',
    method: 'post',
    data
  })
}

// 取消用户角色分配
export function authUserCancel(data) {
  return request({
    url: '/role/authUser/cancel',
    method: 'post',
    data
  })
}

// 批量取消用户角色分配
export function authUserCancelAll(data) {
  return request({
    url: '/role/authUser/cancelAll',
    method: 'post',
    data
  })
}
